// pages/employee/employee.js
const app = getApp();
const util = require('../../utils/util');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    /* 用户信息 */
    /* corpUser.is_manage  是否为管理员 0不是 1是 */
    userInfo_share:{},
    /* tabContent数据 */
    contentIndex:'0',  //内容标记
    tabContentData:[
      {
        name:'客户列表',
        id:'0',
        emptyWord:'你还没有新的客户，还需加油推广哦~',
        showListEmpty:false,
        data:[],   //列表数据
        reqFnName:'getMyBrowseLog',  //获取列表数据方法名
        page:1,  //页码
        pageSize:10, //每页条数
      },
      {
        name:'订单管理',
        id:'1',
        emptyWord:'你还没有新的订单，还需加油推广哦~',
        showListEmpty:false,
        data:[],   //列表数据
        reqFnName:'getOrdersForCorpUserid',  //获取列表数据方法名
        page:1,  //页码
        pageSize:10, //每页条数
      },
      {
        name:'营销发券',
        id:'2',
        emptyWord:'你还没有添加优惠券，赶快添加推广吧~',
        showListEmpty:false,
        data:[],   //列表数据
        reqFnName:'getCouponForCreateUser',  //获取列表数据方法名
        page:1,  //页码
        pageSize:10, //每页条数
      }
    ],
    showListEmpty:false,  //显示列表为空的标识
    /* tab数据 */
    tabDatas:[
      {
        name:'今天',
        type:'1'
      },
      {
        name:'昨天',
        type:'2'
      },
      {
        name:'本周',
        type:'3'
      },
      {
        name:'本月',
        type:'4'
      },
      {
        name:'更多',
        type:'5'
      }
    ],
    /* 员工浏览列表参数 */
    browseLogArgs:{
      corp_userid:'',  //员工企业用户id
      start_time:'',  //开始时间
      end_time:'',    //结束时间
      page:1,  //页码
      pageSize:10, //每页条数
      type:'1'  //1、今天，2、昨天，3、本周，4、本月，5、更多
    },
    activeIndex:'1',
    /* 访问量 */
    all_count:0,
    today_count:0,
    /* 更多时段数据弹层 */
    showMoreTime:false,
    /* 订单参数 */
    orderArgs:{
      page:1,
      pageSize:10,
      status:'', //状态:0、未支付，1、已支付，2、取消订单（不传查看全部订单）
      corp_userid:''  //用户id---企业员工
    },
    /* 订单状态 */
    stateDatas:{
      '0':{
        class:'state_dfk',
        txt:'待付款'
      },
      '1':{
        class:'state_common',
        txt:'已支付'
      },
      '2':{
        class:'state_yqx',
        txt:'已取消订单'
      }
    },
    /* 优惠券参数 */
    couponArgs:{
      page:1,
      pageSize:10,
      userid:''
    },
    /* 添加优惠券弹层 */
    /* 日期选择器 */
    pickerStartTime: '',  //开始的日期选择器开始时间
    pickerStartVal:'',
    pickerEndTime: '',  //结束的日期选择器开始时间
    pickerEndVal:'',
    /* 活动条件*/
    activityData:[
      {
        all:'', //满多少
        num:''  //减多少
      }/* ,
      {
        all:'', //满多少
        num:''  //减多少
      },
      {
        all:'', //满多少
        num:''  //减多少
      } */
    ],
    /* 添加优惠券的参数 */
    couponArgsYXFQ:{
      code:'',  //优惠短码
      create_id:'',  //创建人id
      expire_time:'',   //到期时间
      over_price:'',  //满减条件
      price:'',  //满减金额
      userid:'',  //使用人id
    },
    /* 营销发券弹层 */
    showYXFQPop:true,
    /* 切换管理者角色 */
    isManage:'',
    pickerManageValue:'',
    pickerManageData:[
      {
        name:'企业员工',
        id:'0'
      },
      {
        name:'管理员',
        id:'1'
      }
    ],
    /* 宣传的分类数据 */
    productTypes:[
      {
        name:"企业信息",
        src:"../../assets/images/employee-manager_icon_com.png",
        pagePath:"/pages/companyInfo/companyInfo",
        flag:"fromEmployeeToCompanyInfo",
        class_id:""  //分类id   
      },
      {
        name:"官网介绍",
        src:"../../assets/images/employee-manager_icon_ow.png",
        pagePath:"/pages/owModify/owModify",
        flag:"fromEmployeeToOwModify",
        class_id:"A9XDDFIM86JH8Y43445S"  //分类id   A9XDDFIM86JH8Y43445S
      },
      {
        name:"产品管理",
        src:"../../assets/images/employee-manager_icon_pro.png",
        pagePath:"/pages/propagandaList/propagandaList",
        flag:"fromEmployeeToPropagandaList",
        index:0,
        class_id:"XCUNUBRDWP63EA7469GS"  //分类id
      },
      /* {
        name:"经典案例",
        src:"../../assets/images/employee-manager_icon4.png",
        pagePath:"/pages/propagandaList/propagandaList",
        index:1,
        class_id:"Q1PCWPKKR92HV2CA3510"  //分类id
      },
      {
        name:"其它服务",
        src:"../../assets/images/employee-manager_icon5.png",
        pagePath:"/pages/propagandaList/propagandaList",
        index:2,
        class_id:"TCCPIFCK2T9I813UXP7X"  //分类id
      }, */
      {
        name:"订单管理",
        src:"../../assets/images/employee-manager_icon_order.png",
        pagePath:"",
        flag:"",
        class_id:""  //分类id
      },
      {
        name:"退款处理",
        src:"../../assets/images/employee-manager_icon_exit.png",
        pagePath:"",
        flag:"",
        class_id:""  //分类id  
      },
      {
        name:"客户管理",
        src:"../../assets/images/employee-manager_icon_cus.png",
        pagePath:"/pages/customerManage/customerManage",
        flag:"fromEmployeeToCustomerManage",
        class_id:""  //分类id   
      },
      {
        name:"员工管理",
        src:"../../assets/images/employee-manager_icon_emp.png",
        pagePath:"/pages/employeeManage/employeeManage",
        flag:"fromEmployeeToEmployeeManage",
        class_id:""  //分类id
      },
      {
        name:"数据分析",
        src:"../../assets/images/employee-manager_icon_data.png",
        pagePath:"",
        flag:"",
        class_id:""  //分类id
      }
    ]
  },
  /* 跳转至宣传图片操作页面 */
  goToPropagandaPage(e){
    //
    const { info } = e.currentTarget.dataset;
    console.log(info);
    if(info.pagePath&&info.flag){
      app.globalData[info.flag] = true;
      wx.navigateTo({
        url: `${info.pagePath}`,
        success:res=>{
          res.eventChannel.emit(`${info.flag}`,info)
        }
      });
    }else{
      wx.showToast({
        icon:"none",
        title: "暂未开放",
      })
    }
  },
  /* 切换企业员工-管理员 */
  changeManageRole(e){
    console.log(e);
    let id = this.data.pickerManageData[e.detail.value*1].id;
    app.globalData.is_manager = id;
    this.setData({
      isManage:this.data.pickerManageData[e.detail.value*1].id
    });
    //企业员工
    if(id=='0'){
      //获取名片访问量数据
      this.getVisitCount(this.data.userInfo_share.corpUser.userid);
    }
    //管理员
    if(id=='1'){
      //获取名片访问量数据
      this.getVisitCount();
    }
  },
  /* 删除优惠券 */
  deleteCoupon:function(e){
    let { info } = e.currentTarget.dataset;
    console.log(info);
    return new Promise((resolve,reject)=>{
      wx.showModal({
        title:'提示',
        content:'确定要删除该优惠券吗？',
        success:res=>{
          if(res.confirm){
            resolve();
          }
          if(res.cancel){

          }
        }
      })
    }).then(()=>{
      return app.globalData.$http.call(this,{
        api:"/deleteCoupon",
        data:{
          coupon_id:info.coupon_id
        }
      }).then(res=>{
        console.log(res)
        if(res.data.code=='1'){
          this.pageContentRefresh();
          this.setData({
            showYXFQPop:true
          })
          return Promise.resolve()
        }else{
          return Promise.reject('删除优惠券失败');
        }
      }).catch(err=>{
        return Promise.reject('删除优惠券失败');
      })
    }).then(()=>{
      return this.getCouponForCreateUser()
    }).catch(err=>{

    });
  },
  /* 复制券码 */
  copyCode:function(e){
    wx.setClipboardData({
      data: e.currentTarget.dataset.info.code,
      success: function (res) {
        wx.getClipboardData({
          success: res => {
            //console.log(res);
            wx.showToast({
              title: '复制成功'
            })
          }
        })
      },
      fail: err => {

      }
    })
  },
  /* 添加优惠券 */
  insertCoupon:function(){
    //
    if(!this.data.pickerEndVal){
      wx.showToast({
        icon:'none',
        title:'请选择活动结束时间'
      });
      return;
    }
    //
    if(!this.data.activityData[0].all){
      wx.showToast({
        icon:'none',
        title:'请填写满减条件'
      });
      return;
    }
    //
    if(!this.data.activityData[0].num){
      wx.showToast({
        icon:'none',
        title:'请填写满减条件'
      });
      return;
    }
    //
    wx.showLoading({
      title:"添加优惠券",
      mask:true
    });
    //
    this.setData({
      'couponArgsYXFQ.code':'',
      'couponArgsYXFQ.create_id':this.data.userInfo_share.corpUser.userid,
      'couponArgsYXFQ.expire_time':this.data.pickerEndVal,
      'couponArgsYXFQ.over_price':this.data.activityData[0].all*100,
      'couponArgsYXFQ.price':this.data.activityData[0].num*100,
    });
    console.log(this.data.couponArgsYXFQ);
    //return;
    //
    return app.globalData.$http.call(this,{
      api:"/insertCoupon",
      data:this.data.couponArgsYXFQ
    }).then(res=>{
      wx.hideLoading();
      console.log(res)
      if (res.data.code == '1') {
        let tmpATTData = this.data.activityData;
        tmpATTData.forEach(item=>{
          item.all = '';
          item.num = '';
        });
        this.setData({
          activityData: tmpATTData
        });
        //
        this.pageContentRefresh();
        this.setData({
          showYXFQPop:true
        })
        return Promise.resolve()
      } else {
        return Promise.reject(res.data.msg)
      }
    }).catch(err=>{
      wx.hideLoading();
      //console.log(err);
      return Promise.reject('添加优惠券失败');
    });
  },
  /* 修改满多少的金额 */
  changeAllPrice:function(e){
    //console.log(e.currentTarget.dataset.index);
    //console.log(e.detail.value);
    let index = e.currentTarget.dataset.index*1;
    let value = e.detail.value;
    let regx = /\.\d{3,}/g;
    if(regx.test(value)){
      value = value.slice(0,value.lastIndexOf('.')+3);
    }
    //
    this.setData({
      [`activityData[${index}].all`]:value
    });
    //
    console.log(this.data.activityData);
  },
  /* 修改减多少的金额 */
  changeNumPrice:function(e){
    let index = e.currentTarget.dataset.index*1;
    let value = e.detail.value;
    let regx = /\.\d{3,}/g;
    if(regx.test(value)){
      value = value.slice(0,value.lastIndexOf('.')+3);
    }
    //
    /* if(value>this.data.activityData[index].all){
      wx.showToast({
        icon:"none",
        title:"减少金额不能大于达标金额"
      });
      this.setData({
        [`activityData[${index}].num`]:""
      });
      return;
    } */
    //
    this.setData({
      [`activityData[${index}].num`]:value
    });
    //
    //console.log(this.data.activityData);
  },
  /* 修改开始时间 */
  changeStartTimeYXFQ:function(e){
    console.log(e.detail.value);
    this.setData({
      pickerStartVal: e.detail.value
    })
  },
  /* 修改结束时间 */
  changeEndTimeYXFQ:function(e){
    //console.log(e.detail.value);
    this.setData({
      pickerEndVal: e.detail.value
    })
  },
  /*  */
  closeYSFQPop:function(){
    this.setData({
      showYXFQPop:true
    });
  },
  /*  */
  openYSFQPop:function(){
    this.setData({
      showYXFQPop:false
    });
  },
  /* 跳转到小程序详情 */
  goToMiniDetail:function(e){
    let { info } = e.currentTarget.dataset;
    wx.navigateTo({
      url:'/pages/miniDetail/miniDetail',
      success:res=>{
        res.eventChannel.emit('fromEmployeePage',{
          order_id:info.order_id,
          pageFrom:'employee'
        })
      }
    })
  },
  /* 跳转到订单详情 */
  goToOrderDetail:function(e){
    //console.log(e.currentTarget.dataset.info);
    let { info } = e.currentTarget.dataset;
    wx.navigateTo({
      url:'/pages/orderModify/orderModify',
      success:res=>{
        res.eventChannel.emit('fromEmployeePage',{
          order_id:info.order_id,
          pageFrom:'employee'
        })
      }
    })
  },
  /* 切换显示内容 */
  changeTabContent:function(e){
    //
    let { index,info } = e.currentTarget.dataset;
    //
    this.setData({
      contentIndex:index
    });
    //
    let tabContentData = this.data.tabContentData;
    tabContentData.forEach(item=>{
      item.showListEmpty = false;
    });
    this.setData({
      tabContentData:tabContentData
    });
    //切换显示列表无数据时请求数据
    if(!this.data.tabContentData[this.data.contentIndex*1].data.length){
      if(this.data.contentIndex=='0'&&this.data.activeIndex=='5'){
        return;
      }
      this[this.data.tabContentData[this.data.contentIndex*1].reqFnName]();
    }
    //
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  /* 跳转至访问详情 */
  goToVisitDetail:function(e){
    let { info } = e.currentTarget.dataset;
    wx.navigateTo({
      url: '/pages/visitDetail/visitDetail',
      success:res=>{
        res.eventChannel.emit('fromEmployeeToVisitDetail',{
          info:info
        });
      }
    })
  },
  /* 通过userid获取已创建的优惠券 */
  getCouponForCreateUser:function(){
    //
    this.setData({
      'couponArgs.page':this.data.tabContentData[this.data.contentIndex*1].page,
      'couponArgs.userid':this.data.userInfo_share.corpUser.userid
    });
    //
    wx.showLoading({
      title:'获取优惠券数据',
      mask:true
    });
    //
    return app.globalData.$http.call(this,{
      api:"/getCouponForCreateUser",
      data:this.data.couponArgs
    }).then(res=>{
      console.log(res);
      wx.hideLoading();
      if(res.data.code=='1'){
        if(res.data.body.length){
          let tmpData = this.data.tabContentData[this.data.contentIndex*1].data;
          let page = this.data.tabContentData[this.data.contentIndex*1].page;
          res.data.body.forEach(item=>{
            //
            item.expire_time = app.globalData.dateFormat2(item.expire_time);
            //
            tmpData.push(item);
          });
          page++;
          //
          this.setData({
            [`tabContentData[${this.data.contentIndex*1}].page`]:page,
            [`tabContentData[${this.data.contentIndex*1}].data`]:tmpData,
            [`tabContentData[${this.data.contentIndex*1}].showListEmpty`]:false
          });
        }
        //列表为空
        if(!res.data.body.length&&!this.data.tabContentData[this.data.contentIndex*1].data.length){
          //
          this.setData({
            [`tabContentData[${this.data.contentIndex*1}].showListEmpty`]:true
          });
        }
        return Promise.resolve()
      }else{
        wx.showToast({
          icon:'none',
          title:'获取企业员工关联的优惠券数据失败'
        });
      }
    }).catch(err=>{
      wx.hideLoading();
      //console.log(err);
      wx.showToast({
        icon:'none',
        title:'获取企业员工关联的优惠券数据失败'
      });
    });
  },
  /* 获取与员工相关的客户订单数据 */
  getOrdersForCorpUserid:function(){
    //
    this.setData({
      'orderArgs.page':this.data.tabContentData[this.data.contentIndex*1].page,
      'orderArgs.corp_userid':this.data.userInfo_share.corpUser.userid
    });
    //
    wx.showLoading({
      title:'获取订单数据',
      mask:true
    });
    //
    return app.globalData.$http.call(this,{
      api:"/getOrdersForCorpUserid",
      data:this.data.orderArgs
    }).then(res=>{
      console.log(res);
      wx.hideLoading();
      if(res.data.code=='1'){
        if(res.data.body.length){
          let tmpData = this.data.tabContentData[this.data.contentIndex*1].data;
          let page = this.data.tabContentData[this.data.contentIndex*1].page;
          res.data.body.forEach(item=>{
            //
            item.instime = app.globalData.dateFormatYMDHM(item.instime);
            //
            item.show_price = app.globalData.showPrice(item.price);
            tmpData.push(item);
          });
          page++;
          //
          this.setData({
            [`tabContentData[${this.data.contentIndex*1}].page`]:page,
            [`tabContentData[${this.data.contentIndex*1}].data`]:tmpData,
            [`tabContentData[${this.data.contentIndex*1}].showListEmpty`]:false
          });
        }
        if(!res.data.body.length&&this.data.tabContentData[this.data.contentIndex*1].page>1){
          
        }
        //列表为空
        if(!res.data.body.length&&!this.data.tabContentData[this.data.contentIndex*1].data.length){
          //
          this.setData({
            [`tabContentData[${this.data.contentIndex*1}].showListEmpty`]:true
          });
        }
        return Promise.resolve()
      }else{
        wx.showToast({
          icon:'none',
          title:'获取企业员工关联的订单数据失败'
        });
      }
    }).catch(err=>{
      wx.hideLoading();
      wx.showToast({
        icon:'none',
        title:'获取企业员工关联的订单数据失败'
      });
    })
  },
  /* 更多弹层的时间选择 */
  changeMoreTime(e){
    console.log(e);
    /* 
      e.detail.endTime: "2020-07-16"
      e.detail.startTime: "2020-07-11"
    */
    this.setData({
      'browseLogArgs.end_time':e.detail.endTime,
      'browseLogArgs.start_time':e.detail.startTime
    });
    //
    this.getMyBrowseLog();
  },
  /* 获取名片访问量 */
  getVisitCount:function(userid=""){
    return app.globalData.$http.call(this,{
      api:"/getVisitCount",
      data:{
        userid: userid
      }
    }).then(res=>{
      console.log(res)
      if(res.data.code=='1'){
        this.setData({
          all_count:res.data.body.all_count,
          today_count:res.data.body.today_count
        });
        return Promise.resolve()
      }else{
        wx.showToast({
          icon:'none',
          title:'获取名片访问量数据失败'
        });
      }
    }).catch(err=>{
      return Promise.reject('获取名片访问量数据失败');
    })
  },
  /* 获取企业员工浏览列表 */
  getMyBrowseLog:function(){
    //
    wx.showLoading({
      title:'获取客户数据',
      mask:true
    });
    //
    this.setData({
      'browseLogArgs.page':this.data.tabContentData[this.data.contentIndex*1].page,
      'browseLogArgs.corp_userid':this.data.userInfo_share.corpUser.userid
    });
    //
    return app.globalData.$http.call(this,{
      api:"/getMyBrowseLog",
      data:this.data.browseLogArgs
    }).then(res=>{
      console.log(res);
      wx.hideLoading();
      if(res.data.code=='1'){
        if(res.data.body.data.length){
          let tmpData = this.data.tabContentData[this.data.contentIndex*1].data;
          let page = this.data.tabContentData[this.data.contentIndex*1].page;
          res.data.body.data.forEach(item=>{
            tmpData.push(item);
          });
          page++;
          //
          this.setData({
            [`tabContentData[${this.data.contentIndex*1}].page`]:page,
            [`tabContentData[${this.data.contentIndex*1}].data`]:tmpData,
            [`tabContentData[${this.data.contentIndex*1}].showListEmpty`]:false
          });
        }
        //列表为空
        if(!res.data.body.data.length&&!this.data.tabContentData[this.data.contentIndex*1].data.length){
          //
          this.setData({
            [`tabContentData[${this.data.contentIndex*1}].showListEmpty`]:true
          });
        }
        return Promise.resolve()
      }else{
        wx.showToast({
          icon:'none',
          title:'获取客户列表数据失败'
        });
      }
    }).catch(err=>{
      wx.hideLoading();
      wx.showToast({
        icon:'none',
        title:'获取客户列表数据失败'
      });
    })
  },
  /* 切换客户数据 */
  tabCustomerData:function(e){
    console.log(e.detail.index);
    let type = this.data.tabDatas[e.detail.index].type;
    //
    this.setData({
      activeIndex:type,
      'browseLogArgs.type':type
    });
    //
    let tmpData = this.data.tabContentData[this.data.contentIndex*1].data;
    tmpData.splice(0,tmpData.length);
    let page = this.data.tabContentData[this.data.contentIndex*1].data.page;
    page = 1;
    this.setData({
      [`tabContentData[${this.data.contentIndex*1}].page`]:page,
      [`tabContentData[${this.data.contentIndex*1}].data`]:tmpData
    });
    //显示更多数据弹层
    if(type=='5'){
      this.setData({
        showMoreTime:true
      });
    }else{
      this.setData({
        'browseLogArgs.start_time':'',  //开始时间
        'browseLogArgs.end_time':'',
      });
      //
      this.getMyBrowseLog();
    }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    //获取用户信息
    this.setData({
      userInfo_share:app.globalData.get_userInfo()
    });
    //
    console.log(this.data.userInfo_share);
    this.setData({
      pickerManageValue:app.globalData.is_manager,
      isManage:app.globalData.is_manager
    });
    //企业员工
    if(app.globalData.is_manager=='0'){
      //获取名片访问量数据
      this.getVisitCount(this.data.userInfo_share.corpUser.userid);
      //从添加优惠券页面返回 + 从订单详情返回
      if(app.globalData.fromAAToEmployee||app.globalData.fromOMToEmployee){
        //
        app.globalData.fromAAToEmployee = false;
        app.globalData.fromOMToEmployee = false;
        //
        this.setData({
          contentIndex:1,
          pickerManageValue:'0',
          isManage:'0'
        });
        //
        this.pageContentRefresh();
        return;
      }
      //订单支付失败返回
      if(app.globalData.fromOMPayFailToEmployee){
        //
        app.globalData.fromOMPayFailToEmployee = false;
        //
        this.setData({
          contentIndex:1,
          pickerManageValue:'0',
          isManage:'0'
        });
        //
        this.pageContentRefresh();
        return;
      }
      //从支付成功页返回
      if(app.globalData.fromPSToPE){
        //
        app.globalData.fromPSToPE = false;
        //
        this.setData({
          contentIndex:1,
          pickerManageValue:'0',
          isManage:'0'
        });
        //
        this.pageContentRefresh();
        return;
      }
      //从小程序详情页返回
      if(app.globalData.fromMDToPE){
        //
        app.globalData.fromMDToPE = false;
        //
        this.setData({
          contentIndex:1,
          pickerManageValue:'0',
          isManage:'0'
        });
        //
        this.pageContentRefresh();
        return;
      }
      //从用户浏览信息数据页返回
      if(app.globalData.fromVDToEmployee){
        //
        app.globalData.fromVDToEmployee = false;
        //
        this.setData({
          contentIndex:0,
          pickerManageValue:'0',
          isManage:'0'
        });
        //
        this.pageContentRefresh();
        return;
      }
    }
    //管理员
    if(app.globalData.is_manager=='1'){
      //获取名片访问量数据
      this.getVisitCount();
      //从添加优惠券页面返回 + 从订单详情返回
      if(app.globalData.fromAAToEmployee||app.globalData.fromOMToEmployee){
        //获取名片访问量数据
        this.getVisitCount(this.data.userInfo_share.corpUser.userid);
        //
        app.globalData.fromAAToEmployee = false;
        app.globalData.fromOMToEmployee = false;
        //
        this.setData({
          contentIndex:1,
          pickerManageValue:'0',
          isManage:'0'
        });
        //
        this.pageContentRefresh();
        return;
      }
      //订单支付失败返回
      if(app.globalData.fromOMPayFailToEmployee){
        //获取名片访问量数据
        this.getVisitCount(this.data.userInfo_share.corpUser.userid);
        //
        app.globalData.fromOMPayFailToEmployee = false;
        //
        this.setData({
          contentIndex:1,
          pickerManageValue:'0',
          isManage:'0'
        });
        //
        this.pageContentRefresh();
        return;
      }
      //从支付成功页返回
      if(app.globalData.fromPSToPE){
        //获取名片访问量数据
        this.getVisitCount(this.data.userInfo_share.corpUser.userid);
        //
        app.globalData.fromPSToPE = false;
        //
        this.setData({
          contentIndex:1,
          pickerManageValue:'0',
          isManage:'0'
        });
        //
        this.pageContentRefresh();
        return;
      }
      //从小程序详情页返回
      if(app.globalData.fromMDToPE){
        //获取名片访问量数据
        this.getVisitCount(this.data.userInfo_share.corpUser.userid);
        //
        app.globalData.fromMDToPE = false;
        //
        this.setData({
          contentIndex:1,
          pickerManageValue:'0',
          isManage:'0'
        });
        //
        this.pageContentRefresh();
        return;
      }
      //从用户浏览信息数据页返回
      if(app.globalData.fromVDToEmployee&&this.data.isManage=="0"){
        //
        app.globalData.fromVDToEmployee = false;
        //
        this.setData({
          contentIndex:0,
          pickerManageValue:'0',
          isManage:'0'
        });
        //
        this.pageContentRefresh();
        return;
      }
    }
    console.log("this.data.tabContentData[this.data.contentIndex*1].data.length");
    //打开页面--默认获取客户列表数据
    if(!this.data.tabContentData[this.data.contentIndex*1].data.length){
      typeof this[this.data.tabContentData[this.data.contentIndex*1].reqFnName]==='function'&&this[this.data.tabContentData[this.data.contentIndex*1].reqFnName]();
    }
  },
  /* 下拉刷新 */
  pageContentRefresh:function(){
    //
    this.setData({
      [`tabContentData[${this.data.contentIndex*1}].page`]:1,
      [`tabContentData[${this.data.contentIndex*1}].data`]:[],
    });
    //
    this[this.data.tabContentData[this.data.contentIndex*1].reqFnName]().then(()=>{
      wx.stopPullDownRefresh({
        complete: (res) => {},
      });
    }).catch(()=>{
      wx.stopPullDownRefresh({
        complete: (res) => {},
      });
    });
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    const pages = getCurrentPages();
    if(pages[pages.length - 1].route==='pages/employee/employee'){
      wx.switchTab({
        url: '/pages/index/index',
      })
    }
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    if(this.data.isManage=="1"){
      wx.stopPullDownRefresh({
        complete: (res) => {},
      });
      return;
    }
    this.pageContentRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.isManage=="1")return
    //
    this[this.data.tabContentData[this.data.contentIndex*1].reqFnName]();
  }
})